﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using Website.LopHocService;
using System.Collections.Generic;

namespace Website.SinhVien
{
    public partial class DangKyHocPhan : System.Web.UI.Page
    {
        protected List<LopHocDuocMo> _DanhSachLopHocDuocMo = new List<LopHocDuocMo>();


        public DangKyHocPhan()
        {
            LopHocService.LopHocSoapClient client = new LopHocSoapClient();

            YeuCauDanhSachLopHocDuocMoChoSinhVien YeuCauLopHoc = new YeuCauDanhSachLopHocDuocMoChoSinhVien();
            YeuCauLopHoc.HocKy = 1;
            YeuCauLopHoc.Nam = 2011;
            YeuCauLopHoc.MaSoSinhVien = "0812475";

            this._DanhSachLopHocDuocMo = client.layDanhSachLopHocDuocMoChoSinhVien(YeuCauLopHoc).DanhSachHocPhanDuocMo;
        }


        protected void Page_Load(object sender, EventArgs e)
        {
            if (this.IsPostBack)
            {
                return;
            }


            this.dtgDanhSachLopHoc.DataSource = this._DanhSachLopHocDuocMo;
            this.dtgDanhSachLopHoc.DataBind();
        }

        protected void btnDangKy_Click(object sender, EventArgs e)
        {
            LopHocService.LopHocSoapClient client = new LopHocSoapClient();

            List<YeuCauThemSinhVienVaoLop> DanhSachYeuCau = new List<YeuCauThemSinhVienVaoLop>();

            for (int index = 0; index < this.dtgDanhSachLopHoc.Rows.Count; ++index)
            {
                CheckBox ck = (CheckBox)this.dtgDanhSachLopHoc.Rows[index].FindControl("chkSelect");
                if (ck != null && ck.Checked)
                {
                    YeuCauThemSinhVienVaoLop yeucau = new YeuCauThemSinhVienVaoLop();
                    yeucau.MaLop = this._DanhSachLopHocDuocMo[index].LopID;
                    yeucau.MaSoSinhVien = "0812475";

                    DanhSachYeuCau.Add(yeucau);
                }
            }

            for (int index = 0; index < DanhSachYeuCau.Count; ++index)
            {
                client.themSinhVienVaoLop(DanhSachYeuCau[index]);
            }

            this.Response.Redirect("~/SinhVien/KetQuaDangKyHocPhan.aspx");
        }
    }
}
